home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 183 / dpcs0503.iso / Components / Connector for iCat Commerce Online / data1.cab / Program_Executable_Files / iCat.jar / iCat / iCatBuyNow.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-13  |  5.2 KB  |  156 lines

  1. package iCat;
  2.  
  3. import com.netobjects.nfc.api.CStringArray;
  4. import com.netobjects.nfc.api.ComponentApp;
  5. import com.netobjects.nfc.api.DAssetManager;
  6. import com.netobjects.nfc.api.DDrawPicture;
  7. import com.netobjects.nfc.api.DFile;
  8. import com.netobjects.nfc.api.DImage;
  9. import com.netobjects.nfc.api.DLayout;
  10. import com.netobjects.nfc.api.DMessageBox;
  11. import com.netobjects.nfc.api.DRect;
  12. import com.netobjects.nfc.api.DSite;
  13. import com.netobjects.nfc.api.DSize;
  14. import com.netobjects.nfc.api.IDInspector;
  15. import java.net.URLEncoder;
  16.  
  17. public class iCatBuyNow extends ComponentApp {
  18.    String ItemID = "";
  19.    String strImageFile = "";
  20.    String strReturnURL = "";
  21.    String strReturnURLEncoded = "";
  22.    int Image;
  23.    DDrawPicture cdp;
  24.    String codebase = "";
  25.    DAssetManager assetMan;
  26.  
  27.    public void onCopy() {
  28.       this.assetMan.CopyAsset(this.Image);
  29.    }
  30.  
  31.    protected void finalize() {
  32.       this.assetMan.RemoveAsset(this.Image);
  33.       this.ItemID = null;
  34.       this.strImageFile = null;
  35.       this.strReturnURL = null;
  36.       this.strReturnURLEncoded = null;
  37.       this.cdp = null;
  38.       this.codebase = null;
  39.       this.assetMan = null;
  40.    }
  41.  
  42.    public String onInstall(DAssetManager var1, String var2) {
  43.       this.assetMan = var1;
  44.       this.codebase = var2;
  45.       this.strImageFile = this.codebase + "\\iCatBuyNow.gif";
  46.       return "iCat Buy Now";
  47.    }
  48.  
  49.    public void onUnInstall(DAssetManager var1) {
  50.    }
  51.  
  52.    public void onInspect(CStringArray var1, CStringArray var2) {
  53.       var1.Set("Item ID");
  54.       var2.Set("String");
  55.       var1.Set("Return URL");
  56.       var2.Set("String");
  57.       var1.Set("Image");
  58.       var2.Set("Image");
  59.    }
  60.  
  61.    public String PropertyListener(String var1, String var2, int var3, int var4, IDInspector var5) {
  62.       if (var3 == 1) {
  63.          if (var1.compareTo("Item ID") == 0) {
  64.             return this.ItemID;
  65.          }
  66.  
  67.          if (var1.compareTo("Return URL") == 0) {
  68.             return this.strReturnURL;
  69.          }
  70.  
  71.          if (var1.compareTo("Image") == 0) {
  72.             return Integer.toString(this.Image);
  73.          }
  74.       } else {
  75.          if (var1.compareTo("Item ID") == 0) {
  76.             this.ItemID = var2;
  77.          } else if (var1.compareTo("Return URL") == 0) {
  78.             this.strReturnURL = var2;
  79.             this.strReturnURLEncoded = URLEncoder.encode(var2);
  80.          } else if (var1.compareTo("Image") == 0) {
  81.             this.assetMan.RemoveAsset(this.Image);
  82.             this.Image = Integer.parseInt(var2, 10);
  83.             this.strImageFile = this.assetMan.GetAssetLocation(this.Image, 1, 1);
  84.             DImage var6 = new DImage();
  85.             var6.setImageFile(this.strImageFile);
  86.             DSize var7 = var6.getSize();
  87.             this.cdp.SetSize(var7.getWidth(), var7.getHeight());
  88.             this.cdp.setImageFile(this.assetMan.GetAssetLocation(this.Image, -1, 1));
  89.          }
  90.  
  91.          this.cdp.Invalidate(true);
  92.       }
  93.  
  94.       if (var5 != null) {
  95.          var5.OnPropertyChanged(-1);
  96.       }
  97.  
  98.       return "";
  99.    }
  100.  
  101.    public void onDrop(DLayout var1, DRect var2, int var3) {
  102.       if (var3 == 1) {
  103.          this.cdp = new DDrawPicture();
  104.          this.cdp.SetPositionRect(var2.getLeft(), var2.getTop(), var2.getRight(), var2.getBottom());
  105.          this.cdp.SetStyle(1, 1);
  106.          this.cdp.setStretch(2);
  107.          this.cdp.setUsePictureText(false);
  108.          DImage var4 = new DImage();
  109.          var4.setImageFile(this.strImageFile);
  110.          DSize var5 = var4.getSize();
  111.          this.cdp.SetSize(var5.getWidth(), var5.getHeight());
  112.          this.cdp.setImageFile(this.strImageFile);
  113.          var1.AddObject(this.cdp);
  114.       }
  115.    }
  116.  
  117.    public void onPublish(DAssetManager var1, int var2) {
  118.       String var4 = this.readiCatFile();
  119.       if (this.ItemID.length() == 0) {
  120.          DMessageBox var5 = new DMessageBox();
  121.          var5.Warning("The Item ID property of an iCatBuyNow component in your site is not filled in.\r\nPlease enter this value and republish your site.\r\n");
  122.       }
  123.  
  124.       String var3 = "<A HREF=\"" + var4 + "/index.icl?execute=plugins--cart_addtoorder.icl&itmid=" + this.ItemID;
  125.       if (this.strReturnURL.length() != 0) {
  126.          var3 = var3 + "&srcdoc=" + this.strReturnURLEncoded;
  127.       }
  128.  
  129.       var3 = var3 + "\" target=\"_top\" >";
  130.       this.cdp.setAltTag("Add this item to your shopping cart.");
  131.       this.cdp.setHTMLBefore(var3);
  132.       this.cdp.setHTMLAfter("</A>");
  133.    }
  134.  
  135.    public String readiCatFile() {
  136.       String var1 = "";
  137.       DFile var2 = new DFile();
  138.       DSite var3 = new DSite();
  139.       String var4 = var3.getName();
  140.       if (var2.Open(this.codebase + "iCatInfo\\" + var4 + ".txt", 0)) {
  141.          var1 = var2.ReadString(1000);
  142.          var2.Close();
  143.       } else {
  144.          DMessageBox var5 = new DMessageBox();
  145.          var5.Warning("The iCatCart component requires that you also use\r\nthe iCatBuilt or iCatAffiliate component on your site.\r\n\r\nPlease add one of these components to your site and republish.\r\n");
  146.       }
  147.  
  148.       return var1;
  149.    }
  150.  
  151.    private void debug(String var1) {
  152.       DMessageBox var2 = new DMessageBox();
  153.       var2.Warning(var1 + "\r\n");
  154.    }
  155. }
  156.